//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {},
    isLogin:false,
    showBadge:false,
    meList:[
      {
        text:'借入的图书',
        icon:'../../assets/img/iconfont-dingdan.png',
        url:'../bookList/bookList'
      },
            {
        text:'借出的图书',
        icon:'../../assets/img/iconfont-help.png',
        url:''
      },
            {
        text:'预约的图书',
        icon:'../../assets/img/iconfont-icontuan.png',
        url:''
      },
            {
        text:'飘流的图书',
        icon:'../../assets/img/iconfont-kefu.png',
        url:''
      },
            {
        text:'曾经拥有的图书',
        icon:'../../assets/img/iconfont-tuihuo.png',
        url:''
      },
    ]
  },

  DIYLogin:function(){
    // console.log('点击了登陆')
    wx.navigateTo({
      url: '../login/login'
    });
  },

  onShow: function () {
    console.log('onLoad')
    // 获取openid
    // openid =  wx.getStorageSync('openid')
    // try {
      var openid = wx.getStorageSync('openid')
      if(openid){
        console.log(openid)
        // isLogin = true
        this.setData({
          isLogin:true
        })
      }else{
        this.DIYLogin()
      }
        

       
    // } catch (e) {
    //   // 没有获取到openid,则跳转到注册页
    //   this.DIYLogin()
    // }

    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      console.log(userInfo)
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })

  }
})
